#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys
import yaml
import verifyer
import puller
import syncer
import logging

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S'
                    )


PATH = os.path.abspath(os.path.dirname(sys.argv[0])) + '/'
CONFIG = PATH + 'config.yaml' 
if os.path.exists(CONFIG):
    with open(CONFIG) as file:
        li = yaml.load(file.read())
else:
    logging.info('config file : ' + CONFIG + ' doesn\'t exists!')
    raise Exception(CONFIG + 'config file doesn\'t exists')
if li['WORKINGDIR'] is None or li['CONFIG_NAME'] is None \
        or li['DONE_NAME'] is None or li['VERIFY_NAME'] is None \
        or li['MD5_NAME'] is None or li['BASE_URL'] is None:
    raise Exception('something is empty with ', CONFIG)


if __name__ == '__main__':
    verifyer.init(puller.init(syncer.init(CONFIG)))
    syncer.sync()
    puller.pull()
    puller.pull()
    verifyer.verify()
